﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using GA.Server.ApiInfo;

namespace GA.Server.Api
{
    public class ApiInfoAchievements : SignedApiCall
    {
        public IEnumerable<ApiAchievement> Achievements { get; private set; }

        public ApiInfoAchievements()
        {
        }

        public ApiInfoAchievements(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int playerId)
        {
            LoadSignedApiCall(string.Format("p={0}", playerId));
            XmlNodeList characterNodes = XmlDocument.GetElementsByTagName("a:get_player_achievementsResult");
            if (characterNodes.Count > 0)
            {
                List<ApiAchievement> achievements = new List<ApiAchievement>();
                foreach (XmlNode characterNode in characterNodes)
                {
                    achievements.Add(new ApiAchievement(characterNode.CreateNavigator().ReadSubtree()));
                }
                Achievements = achievements;
            }
        }

        protected override string ApiCallName
        {
            get { return "Achievements"; }
        }
    }
}
